package org.bai.algorithm.day03;

/**
 * @ClassName ReplaceSpace
 * @Description <a href="https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/">替换空格</a>
 * @Author bai
 * @Date 2021/8/12 0:24
 * @Version 1.0
 **/
public class ReplaceSpace {

    public static String replaceSpace(String s) {
        if (null == s || "".equals(s)) {
            return s;
        }

        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (' ' == c) {
                stringBuilder.append("%20");
            } else {
                stringBuilder.append(c);
            }
        }
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        String s = "We are happy.";
        System.out.println(replaceSpace(s));
    }
}
